<extend name="./public/frame.html"/>
<block name="content">
    <div class="layui-inline">
        <div class="layui-col-xs3">
            <div class="layui-inline">
                <input type="text" class="layui-input date" readonly id="start" placeholder="提现申请时间-起">
            </div>
            <div class="layui-inline">
                <input type="text" class="layui-input date" readonly id="end" placeholder="提现申请时间-止">
            </div>
        </div>

        <div class="layui-col-xs5">
            <div class="layui-row">

                <div class="layui-col-xs2">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="drive_name" placeholder="司机姓名">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="required|title" required placeholder="手机号"  class="layui-input" id="driver_phone">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-col-xs2">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="account_number" placeholder="提现账（卡）号">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-col-xs2">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select id="pay_status" class="layui-input">
                                    <option value="">状态</option>
                                    <volist name="pay_status" id="key">
                                        <option value="{$key}">{$pay_status[$key]}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs4 layui-col-md4 layui-col-lg4">
            <div class="layui-btn-group">
                <button class="layui-btn" data-type="search">搜索</button>
                <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
                <a href="javascript:void(0)" class="lea_but" id="withdraw_batch_info"><button class="layui-btn" style="background-color: #5FB878" data-type="withdraw_batch_info">批量支付</button></a>
                <a href="javascript:void(0)" class="lea_but" id="flow_list"><button class="layui-btn layui-btn-xs4" style="background-color:#1E9FFF;"><span style="color:#fff">支付流水</span></button></a>
                <button class="layui-btn layui-btn-warm" data-type="excel">导出数据</button>
            </div>
        </div>
    </div>

    <table class="layui-table" lay-data="{cellMinWidth: 80, height:'auto', url:'{$url}', page: true,limit: 10, id:'cash'}" lay-filter="cash">
        <thead>
        <tr>
            <th lay-data="{field:'id', width:60, sort: true,align:'center'}">ID</th>
            <th lay-data="{field:'driver_id', width:100, sort: true, fixed: true,align:'center'}">司机ID</th>

            <th lay-data="{field:'driver_name', width:80,}">姓名</th>
            <th lay-data="{field:'driver_phone', width:120,align:'center'}">手机号</th>
            <th lay-data="{field:'real_name', width:100,}">支付宝姓名</th>
            <th lay-data="{field:'bank_num', width:140,}">支付宝账号</th>

            <th lay-data="{field:'add_time', width:160, sort: true,align:'center'}">申请时间</th>
            <th lay-data="{field:'money', width:120, sort: true,align:'center'}">提现金额</th>
            <th lay-data="{field:'admin_name', width:100,align:'center'}">审核人员</th>
            <th lay-data="{field:'admin_time', width:160, sort: true,align:'center'}">审核通过时间</th>
            <th lay-data="{field:'admin_pay_time', width:160, sort: true,align:'center'}">处理时间</th>
            <th lay-data="{fixed:'right',field:'pay_status', width:100,align:'center', templet: '#withdrawStatus'}">状态</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:260, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        {{#if(d.audit_status == 1){ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="single_pay" style="background-color:#5FB878;">单笔支付</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="single_check">人工处理</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="deal_log" style="background-color:#FFB800;">操作记录</a>
        {{#}else if(d.audit_status == 2){ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="deal_log" style="background-color:#FFB800;">操作记录</a>
        {{#}else if(d.audit_status == 9){ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="deal_log" style="background-color:#FFB800;">操作记录</a>
        {{#}}}
    </script>
    <script type="text/html" id="withdrawStatus">
        {{#if(d.audit_status==1){}}<span style="color: #5FB878">待支付</span>
        {{#}else if(d.audit_status==2){ }}已支付
        {{#}else if(d.audit_status==9){ }}<span style="color: red;">支付失败</span>
        {{#}else{}}<span style="color: #FFB800">支付失败</span>
        {{#}}}
    </script>


    <script type="application/javascript">
        layui.use(['table', 'laydate', 'form'], function () {
            var table = layui.table
                , form = layui.form
                , laydate = layui.laydate;

            table.render({
                elem:"#cash",
                url:"{:url('/admin/driver_withdraw/table')}",
//                page:true,
//                limit:10,
//                done: function(res, curr, count){
//                    _cur_page = curr;
//                    _cur_limit =res['limit'];
//                }
            });

            lay('.date').each(function () {
                laydate.render({
                    elem: this,
                    type: 'date',
                    trigger: 'click',
                });
            });


            //点击查看 支付流水
            $(document).on('click', '#flow_list', function(){
                layer.open({
                    type: 2,
                    title: '查看支付流水',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['1000px', '65%'],
                    content: '{:url("/admin/driver_withdraw/flowList")}'
                });
            })


            //点击查看 批量支付信息
            $(document).on('click', '#withdraw_batch_info', function(){
                layer.open({
                    type: 2,
                    title: '批量支付信息',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['100%', '100%'],
                    content: '{:url("/admin/driver_withdraw/withdrawTable")}',
                    end: function () {
                        window.location.reload();
                    }
                });
            })

            //监听工具条
            table.on('tool(cash)', function (obj) {
                var data = obj.data; //获得当前行数据
                var id = data.id;
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                if (layEvent === 'single_check') {
                    layer.open({
                        type: 2,
                        title: '审核信息查看',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/driver_withdraw/withdrawSingleCheck","id=")}' + id //iframe的url
                    });
                }

                if (layEvent === 'single_pay') {
                    layer.confirm('是否单笔提现？！', function () {
                        $.post('/admin/driver_withdraw/withdrawSingle', {'id': id}, function (res) {
                            switch (res['code']) {
                                case 1:
                                    layer.alert(res['msg'] + ':' + res['money'] + '元');
                                    setTimeout(function(){  //使用  setTimeout（）方法设定定时
                                        window.location.reload();//页面刷新
                                    },2000);
                                    break;
                                default:
                                    layer.msg(res['msg'], {icon: 5});
                                    setTimeout(function(){  //使用  setTimeout（）方法设定定时
                                        window.location.reload();//页面刷新
                                    },2000);
                                    break;
                            }
                        }, 'json');
                    });
                }

                if (layEvent === 'flow_list') {
                    layer.open({
                        type: 2,
                        title: '支付流水',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['65%', '65%'],
                        content: '{:url("/admin/driver_withdraw/flowList")}', //iframe的url
//                        cancel: function (index, layero) {
//                            table.reload('invoice', {url: '/admin/frWind/index'});
//                        }
                    });
                }

                if (layEvent === 'deal_log') {
                    layer.open({
                        type: 2,
                        title: '查看操作记录',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/driver_withdraw/dealLog","id=")}' + id //iframe的url
                    });
                }


            });

            var active = {
                search: function () {
                    var driver_name = layui.jquery.trim($('#drive_name').val());
                    var driver_phone = layui.jquery.trim($('#driver_phone').val());
                    var account_number = layui.jquery.trim($('#account_number').val());
                    var driver_type = $('#driver_type').val();
                    var pay_status = $('#pay_status').val();
                    var start = $('#start').val();
                    var end = $('#end').val();
                    var reset = $('#reset');
                    if (driver_name || driver_phone || account_number || driver_type ||pay_status || start || end) {
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('cash', {
                            url: '/admin/driver_withdraw/searchIndex',
                            where: {
                                driver_phone: driver_phone,
                                driver_name: driver_name,
                                account_number: account_number,
                                driver_type : driver_type,
                                pay_status: pay_status,
                                start: start,
                                end: end
                            }
                        });
                    } else {
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        alert('搜索项不能为空');
                    }
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('cash', {
                            url: '/admin/driver_withdraw/table?action=index', where: {}
                        });
                    }
                    $('.layui-input').each(function () {
                        $(this).val('');
                    });
                    $('.layui-this').each(function () {
                        $(this).removeClass('layui-this');
                    });
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
                , excel: function () {
                    var headers = {
                        'id' : 'ID',
                        'driver_type' : '司机类型',
                        'driver_id' : 'UID',
                        'w_common_id' : '提现流水号',
                        'driver_name' : '姓名',
                        'driver_phone' : '手机号',
                        'alipay_username' : '支付宝姓名',
                        'alipay_account' : '支付宝账号',
                        'wind_add_time' : '申请时间',
                        'money' : '总提现金额',
                        'balance_withdraw' : '收入提现金额',
                        'award_withdraw' : '奖励提现金额',
                        'admin_name' : '审核人员',
                        'add_time' : '审核通过时间',
                        'pay_admin_name' : '财务人员',
                        'pay_status' : '支付状态',
                        'admin_time' : '处理时间'
                    };
                    var header_str = JSON.stringify(headers);
                    var start = $('#start').val(),
                        end = $('#end').val(),
                        driver_name = $('#drive_name').val(),
                        driver_phone = $('#driver_phone').val(),
                        account_number = $('#account_number').val(),
                        driver_type = $('#driver_type').val();
                        pay_status = $('#pay_status').val();
                    var str = "&start="+start+"&end="+end+"&driver_name="+driver_name+"&driver_phone="+driver_phone+"&account_number="+account_number+"&pay_status="+pay_status+"&driver_type="+driver_type;
                    layer.confirm('请选择导出内容:', {
                        btn:['全部数据', '取消']
                        , btn2: function (index, layero) {
                            layer.close(index);
                        }
                    }, function (index, layero) {
                        //按钮【按钮一】的回调
                        location = "{:url('excel','type=1&headers=')}" + header_str + str;
                        layer.close(index);
                    });
                }
            };

            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });

    </script>
</block>
